<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f = "http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui" 
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Home-RefPortal</title>
    </h:head>
    <h:body> 


        <ui:composition template="./BannersAndMenusTemplate.jsf">

            <ui:define name="content">
                <p:panel header="All Authors">  

                    <h:form rendered="#{user.login}" id="form">  

                        <p:dataTable id="dataTable2" var="Author" value="#{user.getallAuthors()}" widgetVar="Author"    
                                     emptyMessage="No Authors found with given criteria" sortBy="#{Author.name}"
                                     selection="#{user.selectedAuthor}" selectionMode="single"  rowKey="#{Author.id}" 
                                     paginator="#{user.checkIfTenOrMore('aut')}" rows="10" rowsPerPageTemplate="10" lazy="false"  
                                     paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" >   

                            <p:ajax event="rowSelect" listener="#{user.onRowSelect}"    
                                    update=":form:dataTable2" />  
                            <p:ajax event="rowUnselect" listener="#{user.onRowUnselect}" update=":form:dataTable2"/>  


                            <f:facet name="footer">    

                                <p:commandButton value="Add" icon="ui-icon-pencil" 
                                                 action = "#{user.gotoAddAuthor()}"/>   

                                <p:growl id="messages" showDetail="true" sticky="false"/>     


                                


                                    <p:commandButton id="showDialogButton" value="Delete" rendered="#{user.renderOnRowSelect}" 
                                                     onclick="confirmation.show()" type="button" icon="ui-icon-close"/>  


                                    <p:confirmDialog id="confirmDialog" message="Are you sure you want to delete the Author?"  
                                                     header="Initiating destroy process" severity="alert" widgetVar="confirmation">  

                                        <p:commandButton id="confirm" value="Yes" update=":form" oncomplete="confirmation.hide()"  
                                                         actionListener="#{user.deleteAuthor}"  ajax="true"/>    
                                        <p:commandButton id="decline" value="No" onclick="confirmation.hide()" type="button" />   

                                    </p:confirmDialog>       



                                    <p:commandButton  value="Edit" icon="ui-icon-pencil"
                                                      action = "#{user.gotoEditAuthor}" rendered="#{user.renderOnRowSelect}"/>

                            </f:facet>    

                            <p:column filterBy="#{Author.name}" sortBy="{Author.name}"   
                                      headerText="Name"  
                                      filterMatchMode="contains">    
                                <h:outputText value="#{Author.name}" />   </p:column> 

                            <p:column  filterBy="#{Author.surname}"    
                                       headerText="Surname"  
                                       filterMatchMode="contains">  
                                <h:outputText value="#{Author.surname}" />  </p:column> 

                            <p:column  filterBy="#{Author.names}"     
                                       headerText="Other names"   
                                       filterMatchMode="contains">  

                                <h:outputText value="#{user.getSample(Author.names)}"  />


                            </p:column>  




                        </p:dataTable> 

                    </h:form>


                </p:panel>
            </ui:define>

        </ui:composition>




    </h:body>
</html>

